package com.cap.dreamcircle.Utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.cap.dreamcircle.App.App;


/**
 * Preference操作工具类
 * Created by liukanshan on 2017/1/1.
 */

public class PreferenceUtils {

    public static String GetUserToken() {
        SharedPreferences preferences = App.GetInstance().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        return preferences.getString("token_key", "");
    }

    public static void SaveUserToken(String token) {
        SharedPreferences preferences = App.GetInstance().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("token_key", token);
        editor.commit();
    }

    public static void SaveUserId(String user_hash) {
        SharedPreferences preferences = App.GetInstance().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("user_id", user_hash);
        editor.commit();
    }

    public static String GetUserId(){
        SharedPreferences preferences = App.GetInstance().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        String user_hash = preferences.getString("user_id", "");
        return user_hash;
    }

    public static void ClearUserInfo() {
        SharedPreferences preferences = App.GetInstance().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.remove("token_key");
        editor.remove("user_id");
        editor.commit();
    }

    public static int GetStartCount(){
        SharedPreferences preferences = App.GetInstance().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        int start_count = preferences.getInt("start_count", 0);
        return start_count;
    }

    public static void SetStartCount(int count){
        SharedPreferences preferences = App.GetInstance().getSharedPreferences("user_info", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt("start_count", count);
        editor.commit();
    }
}
